import React, {Component} from 'react'
import {connect} from 'react-redux'

import {
  odooActionCreators,
  ListViewActions
} from '../redux'
import Posts from '../components/Posts'

const mapStateToProps = (state) => {
  return {
    datas: state.odoo.textDatas,
    loading: state.odoo.textLoading,
    tag: 'text',
  }
}

const mapDispatchToProps = (dispatch) => ({
  onRefresh: () => {
    dispatch(odooActionCreators.getTexts(ListViewActions.REFRESH))
  },
  onLoadMore: () => {
    dispatch(odooActionCreators.getTexts(ListViewActions.LOADMORE))
  },
  onFavoritePress: (data, isFavorited) => {
    const tag = 'text'
    const level = 'favorite'
    if (isFavorited) {
      dispatch(odooActionCreators.delFavoritePost(data.id, tag, level))
    } else {
      dispatch(odooActionCreators.favoritePost(data, tag, level))
    }
  },
  onLikePress: (data, isLiked) => {
    const tag = 'text'
    const level = 'like'
    if (isLiked) {
      dispatch(odooActionCreators.delFavoritePost(data.id, tag, level))
    } else {
      dispatch(odooActionCreators.favoritePost(data, tag, level))
    }
  }
})

export default connect(mapStateToProps,mapDispatchToProps)(Posts)
